Virtualization is a technology that allows an operating system designed to run as the exclusive manager of a hardware platform to run in an isolated container (virtual machine), possibly in parallel with other virtual machines, on a single instance of hardware (a physical machine). The operating system in a virtual machine runs as a “guest” on a host operating system. For much of the time a system is running, a host operating system can simply allow application and guest operating system instructions to execute without modification. However, there are important exceptions. For example, the host operating system may reserve certain areas of physical memory for its exclusive use. The virtualization environment must deny the guest operating system access to these areas of memory, while providing the same response to the guest operating system that it would have received if it had been running directly on the hardware.
Some processors detect and handle instructions that must behave differently in a virtual machine. When such an instruction is detected in the instruction pipeline, a virtualization fault-handling routine can be initiated, e.g., using an interrupt. The fault-handling routine reads a copy of the detected instruction from its main memory location, determines what it was intended to do, and then issues a string of instructions to fulfill the instruction's intention without interfering with the host operating system, e.g., by allowing the guest operating system to access a virtual memory location that it can treat as the intended physical memory location. Then control can be returned to the instruction stream that was executing just before the interrupt.
The interrupt imposes a serious performance penalty, as a single instruction execution has been replaced by two context switches and an instruction handling routine. If the faulting instruction is just one of a series of such instructions and if the faulting instructions are called for repeatedly, the performance hit can be intolerable.
One approach to reducing this performance hit is to replace problematic instructions with “traces” that emulate those instructions. The first time a problematic instruction is encountered, an interrupt is triggered. The virtualization fault handling routine accesses a copy of the instruction in main memory, determines its intent, generates and stores an emulating trace, and replaces the problematic instruction with a branch instruction to the trace. The next time the problematic instruction is called, the emulating trace executes without an interrupt having to be generated. Thus, a significant performance advantage is achieved.
Herein, related art is described to facilitate understanding of the invention. Related art labeled “prior art” is admitted prior art; related art not labeled “prior art” is not admitted prior art.